package com.pzcnet.service;

import com.pzcnet.annotation.CallBackHandler;
import com.pzcnet.annotation.EventHandler;
import com.pzcnet.annotation.EventProcessHandler;
import com.pzcnet.core.CallBack;
import com.pzcnet.model.EventException;
import com.pzcnet.model.EventType;
import com.pzcnet.model.Payload;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * Created by xdkxlk on 2017/8/30.
 */
@Service
@EventHandler
@CallBackHandler(EventType.USER_DEL)
public class TestService extends CallBack {

    @Transactional
    @EventProcessHandler(EventType.USER_DEL)
    public Payload process(String name, int id) throws EventException {
//        throw new EventException(Payload.builder()
//                .addParameter("k", true)
//                .build()
//        );
        return Payload.builder()
                .addParameter("k", true)
                .build();
    }

    @Override
    public void onSuccess(Payload publishPayload, Payload returnPayload) {
        System.out.println("onSuccess");
    }

    @Override
    public void onError(Payload publishPayload, EventException eventException) {
        System.out.println("onError");
    }
}
